﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdDbHandle : IDisposable
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbHandle(IntPtr cPtr, bool cMemoryOwn)
		{
			this.swigCMemOwn = cMemoryOwn;
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbHandle obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbHandle()
		{
			this.Dispose();
		}

		public virtual void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdDbHandle(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
		}

		public static explicit operator ulong(OdDbHandle h)
		{
			return h.ToUInt64();
		}

		public override string ToString()
		{
			if (this.swigCPtr.Handle == IntPtr.Zero)
			{
				return "Empty";
			}
			return this.ToUInt64().ToString("X");
		}

		public OdDbHandle() : this(GlobalsPINVOKE.new_OdDbHandle__SWIG_0(), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdDbHandle(OdDbHandle value) : this(GlobalsPINVOKE.new_OdDbHandle__SWIG_1(OdDbHandle.getCPtr(value)), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdDbHandle(ulong value) : this(GlobalsPINVOKE.new_OdDbHandle__SWIG_2(value), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdDbHandle(string value) : this(GlobalsPINVOKE.new_OdDbHandle__SWIG_3(value), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdDbHandle(int value) : this(GlobalsPINVOKE.new_OdDbHandle__SWIG_4(value), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdDbHandle Assign(ulong value)
		{
			OdDbHandle result = new OdDbHandle(GlobalsPINVOKE.OdDbHandle_Assign__SWIG_0(this.swigCPtr, value), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbHandle Assign(string value)
		{
			OdDbHandle result = new OdDbHandle(GlobalsPINVOKE.OdDbHandle_Assign__SWIG_1(this.swigCPtr, value), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbHandle Assign(OdDbHandle value)
		{
			OdDbHandle result = new OdDbHandle(GlobalsPINVOKE.OdDbHandle_Assign__SWIG_2(this.swigCPtr, OdDbHandle.getCPtr(value)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbHandle Assign(int value)
		{
			OdDbHandle result = new OdDbHandle(GlobalsPINVOKE.OdDbHandle_Assign__SWIG_3(this.swigCPtr, value), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public ulong ToUInt64()
		{
			ulong result = GlobalsPINVOKE.OdDbHandle_ToUInt64(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public string ascii()
		{
			string result = GlobalsPINVOKE.OdDbHandle_ascii(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isNull()
		{
			bool result = GlobalsPINVOKE.OdDbHandle_isNull(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool IsEqual(ulong value)
		{
			bool result = GlobalsPINVOKE.OdDbHandle_IsEqual(this.swigCPtr, value);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool IsNotEqual(ulong value)
		{
			bool result = GlobalsPINVOKE.OdDbHandle_IsNotEqual(this.swigCPtr, value);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbHandle Add(out long value)
		{
			OdDbHandle result = new OdDbHandle(GlobalsPINVOKE.OdDbHandle_Add(this.swigCPtr, out value), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void bytes(byte bytes)
		{
			GlobalsPINVOKE.OdDbHandle_bytes(this.swigCPtr, bytes);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		protected bool swigCMemOwn;
	}
}
